<?php
/**
 * Application level Controller
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       cake
 * @subpackage    cake.cake.libs.controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

/**
 * This is a placeholder class.
 * Create the same file in app/app_controller.php
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       cake
 * @subpackage    cake.cake.libs.controller
 * @link http://book.cakephp.org/view/957/The-App-Controller
 */
class AppController extends Controller {
	
	// add for authentication
	var $components = array(
			'Auth',
          	'Session',
          );
    function beforeFilter() {		
		parent::beforeFilter();
		$this->Auth->loginError = 'Sai tên đăng nhập hoặc mật khẩu';
    	$this->Auth->authError = 'Bạn không có quyền truy cập. Đăng nhập trước khi tiếp tục.';
		$this->Auth->authorize = 'controller';
		$this->Auth->userModel = 'Employee';
		$this->Auth->fields = array('username' => 'user_name', 'password' => 'pass_word');
		$this->Auth->loginAction = array('admin' => true, 'controller' => 'employees', 'action' => 'login');
		$this->Auth->logoutRedirect = array(Configure::read('Routing.admin') => true, 'controller' => 'home', 'action' => 'home');
		$this->Auth->loginRedirect = array(Configure::read('Routing.admin') => true,'controller' => 'Employees', 'action' => 'login');
		$this->Auth->allow('admin_mlogin');
		//$this->Auth->allow('*');
		if(isset($this->params['pass'][0]) && $this->params['pass'][0] == 'm' && $this->action !='admin_mlogin'){
	        if (isset($this->params['pass'][1])) {
	            $this->Session->id($this->params['pass'][1]);
	            $this->Session->start();
	        }
		}
	}
	function isAuthorized() {
	    return true;	
	}
	// add end
}
